package com.easylinkin.linkappapi.hcmy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.hcmy.service.HCMYTrackPlaybackService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.positioning.entity.CarDeviceEs;
import com.easylinkin.linkappapi.hcmy.entity.QueryTrack;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * class info :汉川面源--轨迹回放
 *
 * @author liuqihang
 * @date 2021/10/12 14:29
 */
@RestController
@RequestMapping("/hcmyTrack/playback")
public class HCMYTrackPlaybackController {

    @Resource
    private HCMYTrackPlaybackService hcmyTrackPlaybackService;

    /**
     * 根据时间区间获取轨迹明细流水
     * @param queryTrackRequestModel
     * @return
     */
    @PostMapping("getDetailPage")
    public RestMessage getDetailPage(@RequestBody RequestModel<QueryTrack> queryTrackRequestModel) throws Exception {
        Assert.notNull(queryTrackRequestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(queryTrackRequestModel.getPage(), "page 不能为空");
        IPage<CarDeviceEs> detailPage = hcmyTrackPlaybackService.getDetailPage(queryTrackRequestModel.getPage(), queryTrackRequestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(detailPage).build();
    }

    /**
     * 导出轨迹明细
     * @param queryTrack
     * @param request
     * @param response
     */
    @PostMapping("exportDetail")
    public void exportDetail(@RequestBody QueryTrack queryTrack, HttpServletRequest request, HttpServletResponse response) throws Exception {
        hcmyTrackPlaybackService.exportDetail(queryTrack, request, response);
    }
}
